﻿using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using B.MES.Customer.Infrastructure.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.MES.Customer.Application.Application
{
    /// <summary>
    /// BOM 应用层
    /// </summary>
    public class BOMApplication : BaseApplication<BomTab>, IBOMApplication
    {
        /// <summary>
        ///  BOM 应用层
        /// </summary>
        private readonly IBOMRepository _bomRepository;
        /// <summary>
        ///  构造函数
        /// </summary>
        /// <param name="bomRepository"> BOM仓储</param>
        public BOMApplication(IBOMRepository bomRepository) : base(bomRepository)
        {
            _bomRepository = bomRepository;
        }
        /// <summary>
        /// 添加 BOM 信息方法
        /// </summary>
        /// <param name="bom">参数 bomInfo: 要添加的 BOM 信息对象</param>
        public int AddBom(BOMDto bom)
        {
            return _bomRepository.AddBom(bom);
        }
        /// <summary>
        /// 绑定成品类型
        /// </summary>
        /// <returns>成品类型列表</returns>
        public List<ArtifactType> GetArtifacTypeList()
        {
            return _bomRepository.GetArtifacTypeList();
        }

        /// <summary>
        /// 获取显示、分页、查询Bom列表
        /// </summary>
        /// <param name="bomTopic">Bom主题</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns>Bom列表信息</returns>
        public PageApiResut<BomTab> GetBom(string? bomTopic, int pageIndex, int pageSize)
        {
            return _bomRepository.GetBom(bomTopic, pageSize, pageIndex);
        }
        /// <summary>
        /// 编辑Bom信息
        /// </summary>
        /// <param name="bomId">bom表主键</param>
        /// <returns>返回Bom实体</returns>
        public BomTab GetBomTabById(int bomId)
        {
            return _bomRepository.GetBomTabById(bomId);
        }
        /// <summary>
        /// 修改Bom信息
        /// </summary>
        /// <param name="bom">要添加的 BOM 信息对象</param>
        /// <returns> 受影响行数</returns>
        public int UpdBomInfoById(BomTab bom)
        {
            return _bomRepository.UpdBomInfoById(bom);
        }
        /// <summary>
        /// 获取Bom详情
        /// </summary>
        /// <param name="bomId">bom表主键</param>
        /// <returns> 获取Bom详情</returns>
        public APIResult<BOMDto> GetBomDetail(int bomId)
        {
            return _bomRepository.GetBomDetail(bomId);
        }
        /// <summary>
        /// 显示Bom列表
        /// </summary>
        /// <returns>Bom列表信息</returns>
        public List<BomTab> GetBomList()
        {
            return _bomRepository.GetBomList();
        }
        /// <summary>
        /// 删除Bom信息
        /// </summary>
        /// <param name="bomId">BomId</param>
        /// <returns>受影响行数</returns>
        public int DelBomById(int bomId)
        {
            return _bomRepository.DelBomById(bomId);
        }
        /// <summary>
        /// 获取BOM下的物料信息
        /// </summary>
        /// <param name="bomId"> BomId</param>
        /// <returns> 物料信息</returns>
        public PageApiResut<Material> GetMaterialsByBOMId(int bomId)
        {
            return _bomRepository.GetMaterialsByBOMId(bomId); 
        }
    }
}
